<template>
    <!-- 办理服务订单 -->
    <el-dialog v-model="dialogFormVisible" title="服务人员信息" align-center width="30%" :before-close="handleClose">
        <el-form :model="updateFrom" ref="ruleFormRef" label-width="120px">
            <el-form-item label="姓名">
                <el-select v-model="updateFrom.name" style="width: 200px;" @change="handleStaffChange">
                    <el-option v-for="staff in staffList" :key="staff.name" :label="staff.name" :value="staff.name" />
                </el-select>
            </el-form-item>
            <el-form-item label="联系电话">
                <el-input v-model="updateFrom.telephone" style="width: 200px;" disabled />
            </el-form-item>
            <el-form-item label="备注">
                <el-input type="textarea" v-model="updateFrom.remark" :rows="3" style="width: 200px;" placeholder="请输入备注信息" />
            </el-form-item>
            <!-- <el-form-item label="活动目的">
                <el-input v-model="formData.purpose" style="width: 200px;" />
            </el-form-item> -->
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="cancelDialog">取消</el-button>
                <el-button type="primary" @click="serviceorderStore.updateOrder">
                    提交
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { storeToRefs } from 'pinia'
import { useServiceorderStore } from '../../../stores/serviceorder'
const serviceorderStore = useServiceorderStore()
const { dialogFormVisible, updateFrom } = storeToRefs(serviceorderStore)

// 服务人员列表数据
const staffList = ref([
    { name: '徐康', telephone: '15333333333' },
    { name: '赵大', telephone: '15444444444' },
    { name: '李柏', telephone: '15555555555' },
    { name: '王晓', telephone: '15666666666' }
])

// 处理服务人员选择变化
const handleStaffChange = (selectedName) => {
    const selectedStaff = staffList.value.find(staff => staff.name === selectedName)
    if (selectedStaff) {
        updateFrom.value.telephone = selectedStaff.telephone
    }
}

const cancelDialog = () => {
    serviceorderStore.dialogFormVisible = false
    serviceorderStore.updateFrom = {}
}
const handleClose = () => {
    cancelDialog()
}
</script>

<style scoped>
.el-button--text {
    margin-right: 15px;
}

.dialog-footer button:first-child {
    margin-right: 10px;
}
</style>